﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Microsoft.Health;
using Microsoft.Health.ItemTypes;
using FusionAPI;

namespace PFSync
{
    /// <summary>
    /// Summary description for Height
    /// </summary>
    public class SyncPressure : SyncItem
    {
        public SyncPressure()
        { }

        #region Properties
        /// <summary>
        /// Returns a hashcode that is the unique ID for this item
        /// </summary>
        public override int ID
        {
            get
            {
                int hashCode = DateAdded.GetHashCode();
                hashCode += Diastolic.GetHashCode();
                hashCode += Systolic.GetHashCode();
                hashCode += Pulse.GetHashCode();

                return hashCode;
            }
        }

        /// <summary>
        /// Generate a HealthVault item based on the Value,
        /// Date, and Measurements stored in this object
        /// </summary>
        public override HealthRecordItem HVItem
        {
            get
            {
                BloodPressure item = new BloodPressure();
                item.When = new HealthServiceDateTime(DateAdded);

                item.Diastolic = Diastolic;
                item.Systolic = Systolic;
                item.Pulse = Pulse;

                return item;
            }
        }

        public override ClinicalDataValue PFItem
        {
            get { throw new NotImplementedException(); }
        }

        public override int PFTypeId
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Return the HealthVault Type GUID
        /// </summary>
        public override Guid HVTypeID
        {
            get { return BloodPressure.TypeId; }
        }

        /// <summary>
        /// Gets the Weight value in Kilograms or Lbs depending 
        /// on MeasurementType. Value that is -set- only takes in Kilograms.
        /// </summary>
        public override object Value
        {
            get { return Systolic + "/" + Diastolic + " - " + Pulse + "BPM"; }
            set { }
        }

        /// <summary>
        /// Upper limit value for blood pressure (mmHG)
        /// </summary>
        public int Diastolic { get; set; }

        /// <summary>
        /// Lower limit value for blood pressure (mmHG)
        /// </summary>
        public int Systolic { get; set; }

        /// <summary>
        /// Pulse in Beats per Minute (BPM)
        /// </summary>
        public int Pulse { get; set; }

        /// <summary>
        /// Gets and sets the object's Date
        /// </summary>
        public override DateTime DateAdded { get; set; }
        #endregion

        /// <summary>
        /// Default constructor takes in a date, diastolic/systolic and bpm
        /// </summary>
        /// <param name="date">Date Added</param>
        /// <param name="value">Value of Height</param>
        /// <param name="measurement">Height Measurement</param>
        public SyncPressure(DateTime date, int diastolic, int systolic, int bpm)
        {
            DateAdded = date;
            Diastolic = diastolic;
            Systolic = systolic;
            Pulse = bpm;
        }

        /// <summary>
        /// Constructor takes in a HealthVault BloodPressure item
        /// and converts it to a PFSync item.
        /// </summary>
        /// <param name="hvRecord">HealthVault Weight</param>
        public SyncPressure(BloodPressure hvRecord)
        {
            DateAdded = hvRecord.When.ToDateTime();
            Diastolic = hvRecord.Diastolic;
            Systolic = hvRecord.Systolic;
            Pulse = hvRecord.Pulse.Value;
        }
    }
}
